package com.vrp3d;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger文档配置
 *
 * @author vrp3d
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Configuration {

    /**
     * (线上环境不使用swagger文档)
     * 在不同的环境的配置文件中分别给定boolean值,在下方的方法enable中,不同环境读取到不同值,来决定是否启用swagger文档
     */
    @Value("${swagger.enable}")
    private boolean enableSwagger;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
              .apiInfo(apiInfo())
              .enable(enableSwagger)
              .select()
              .apis(RequestHandlerSelectors.basePackage("com.vrp3d"))
              .paths(PathSelectors.any())
              .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
              .title("网站api文档")
              .description("需要登录接口header中带上Authorization<br>" +
                    "语言选择在header中带上User-Language zh中文 en英文 阿拉伯文ar 日文ja 韩文ko 西班牙语es")
              .version("1.0")
              .build();
    }

}
